package com.retailcloud.baseservice.controller;

import java.util.Arrays;
import java.util.Map;


import com.retailcloud.commonutils.dto.UserDTO;
import com.retailcloud.commonutils.utils.PageUtils;
import com.retailcloud.commonutils.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.retailcloud.baseservice.entity.UsersEntity;
import com.retailcloud.baseservice.service.UsersService;




/**
 * 用户表
 *
 * @author wudi
 * @email 632132852@qq.com
 * @date 2024-11-02 19:41:19
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private UsersService usersService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions(":users:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = usersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    //@RequiresPermissions(":users:info")
    public R info(){
		UserDTO users = usersService.getUserInfoById();

        return R.ok().put("users", users);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions(":users:save")
    public R save(@RequestBody UsersEntity users){
		usersService.save(users);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions(":users:update")
    public R update(@RequestBody UsersEntity users){
		usersService.updateUserInfoById(users);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions(":users:delete")
    public R delete(@RequestBody String[] userIds){
		usersService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

    /**
     * 用来进入初始化进入，没有该用户信息就创建,有用户信息看有没有企业信息
     */
    @RequestMapping("/init")
    public R init(@RequestBody UsersEntity users){

        UserDTO userDTO = usersService.init(users);
        return R.ok().put("data",userDTO);
    }



}
